﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;

namespace MoneyManagerNET.Presentation.ViewModel.Base
{

    public class ViewModelBase<TModel> : ViewModelBase where TModel : class
    {
        public TModel ModelAs { get { return this.Model as TModel; } set { this.Model = value; } }//bad for loose coupling
        public override object Model
        {
            get
            {
                return base.Model;
            }
            set
            {
                base.Model = value;
                this.OnChange(() => ModelAs);
                LoadValues(ModelAs);
            }
        }
        public virtual void LoadValues(TModel m)
        {
            //TODO: create and call helper that uses reflecion
        }

        public virtual TModel PutValues(TModel m)
        {
            //TODO: create and call helper that uses reflecion
            return m;
        }

        public override void LoadValues()
        {
            LoadValues(ModelAs);
        }

        public override object PutValues()
        {
            return PutValues(this.ModelAs);
        }


        public override Type GetModelType()
        {
            return typeof(TModel);
        }



    }

}
